package com.tomatozq163;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class RabbitDemoApplication implements CommandLineRunner {
	@Autowired
	private AmqpTemplate amqpTemplate;

	public static void main(String[] args) {
		SpringApplication.run(RabbitDemoApplication.class, args);
	}

	@Override
	public void run(String... args){
//		Date now = new Date();
//
//		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
//
//		System.out.println("发送消息时间:" + sdf.format(now));
//
//		amqpTemplate.convertAndSend(RabbitMQConfig.NORMAL_EXCHANGE_NAME, RabbitMQConfig.NORMAL_ROUTE_KEY, "向正常队列发消息");
//
//		amqpTemplate.convertAndSend(RabbitMQConfig.DELAY_EXCHANGE_NAME, RabbitMQConfig.DELAY_ROUTE_KEY, "向延时队列发消息", new MessagePostProcessor() {
//			@Override
//			public Message postProcessMessage(Message message) throws AmqpException {
//				//给消息设置延迟毫秒值
//				message.getMessageProperties().setExpiration(String.valueOf(5000));
//
//				return message;
//			}
//		});
	}
}
